<template>
  <div class="about">
    <div class="nav">
      <div>
        <van-icon name="passed" />
        <span>100%正品保证</span>
      </div>
      <div>
        <van-icon name="passed" />
        <span>所有商品精挑细选</span>
      </div>
      <div>
        <van-icon name="passed" />
        <span>售后无忧</span>
      </div>
    </div>
    <div class="jump">
      <h1>
        购买数量<i v-if="commodityList">{{ commodityList.length }}</i>
      </h1>
      <div v-if="!show">
        <span @click="edit">管理</span>
      </div>
       <div v-else>
        <span @click="edit">取消</span>
      </div>
    </div>

    <div class="xian" v-if="!commodityList || commodityList.length == 0">
      <div class="box">
        <img src="http://47.115.51.185/h5/img/noCart.6f2abfef.png" alt="" />
      </div>
      <van-divider
        :style="{ color: '#282828', borderColor: '#282828', padding: '0 70px' }"
      >
        为你推荐
      </van-divider>
      <recommend :recommended="recommended"></recommend>
    </div>
    <div v-else>
      <commodity :show="show" :commodityList="commodityList"></commodity>
    </div>
  </div>
</template>
<script>
import Recommend from "@/components/Recommend.vue";
import Commodity from "@/components/Commodity.vue";
export default {
  data() {
    return {
      recommended: null,
      commodityList: null,
       //用来显示提交订单还是删除选择
      show:false,

     
    };
  },
  watch: {},
  created() {
    this.axios("http://47.115.51.185/api/product/hot?page=1&limit=20").then(
      (re) => {
        // console.log("re",re);
        this.recommended = re;
      }
    );
    this.axios
      .get("/cart/list", {
        headers: {
          "Authori-zation": "Bearer " + localStorage.getItem("token"), //带上登录信息去请求购物车的产品
        },
      })
      .then((re) => {
        re.valid.map((v) => {
          v.checked = false;
        });
        console.log("获取购物车数据", re.valid);
        this.commodityList = re.valid;
      });
  },
  methods: {
    edit() {
      this.show=!this.show
    },
    
  },
  components: {
    Recommend,
    Commodity,
  },
};
</script>
<style lang="less" scoped>
.about {
  padding-bottom: 40px;
  // background-color: #F5F5F5;
  .nav {
    background-color: #f5f5f5;
    display: flex;
    font-size: 12px;
    color: #8c8c8c;
    justify-content: space-around;
    line-height: 38px;
    align-items: center;
    span {
      margin-left: 8px;
    }
  }
  .jump {
    display: flex;
    justify-content: space-between;
    align-items: center;
    h1 {
      background: #fff;
      padding-left: 15px;
      line-height: 40px;
      font-size: 14px;
      color: #282828;
      i {
        color: #fc4141;
      }
    }
    span {
      font-size: 14px;
      margin-right: 25px;
      color: #282828;
      border: 1px solid #282828;
      padding: 2px 10px;
      // height: 20px;
    }
  }

  .xian {
    background-color: #f5f5f5;
    height: 10px;
  }
  .box {
    margin-top: 40px;
    height: 168px;
    img {
      display: block;
      margin: 0 auto;
      height: 100%;
    }
  }
}
</style>
